﻿using Abp.AspNetZeroCore;
using Abp.Dependency;
using Castle.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AbpZeroTemplate
{
    public static class LiscenceSkipInterceptorRegistrar
    {
        public static void Initialize(IIocManager iocManager)
        {
            iocManager.IocContainer.Kernel.ComponentRegistered += (key, handler) =>
            {
                if (ShouldIntercept(iocManager, handler.ComponentModel.Implementation))
                {
                    handler.ComponentModel.Interceptors.Add(new InterceptorReference(typeof(LiscenceSkipInterceptor)));
                }
            };
        }

        private static bool ShouldIntercept(IIocManager iocManager, Type type)
        {
            if (iocManager.IsRegistered(typeof(AbpAspNetZeroCoreModule)) && type == typeof(AbpAspNetZeroCoreModule))
            {
                return true;
            }
            return false;
        }
    }
}
